# Maintainer: Leonidas Spyropoulos (artafinde@archlinux.org)
# Contributor: scrawler@gmail.com

pkgname=freeplane
_majorver=1
_minorver=11
_patchver=8
_updatever=
pkgver=${_majorver}.${_minorver}.${_patchver}
_git_tag=${_majorver}.${_minorver}.${_patchver}
pkgrel=1
pkgdesc="A Java mindmapping tool"
arch=('any')
url="http://freeplane.sourceforge.net"
license=('GPL2')
_jrever=11
_jdkver=17
makedepends=('gradle' "jdk${_jdkver}-openjdk" 'gnu-free-fonts' 'fontconfig' 'unzip')
depends=("java-runtime>=${_jrever}" "java-runtime<=${_jdkver}")
source=("https://downloads.sourceforge.net/sourceforge/${pkgname}/${pkgname}_src-${_git_tag}.tar.gz"
        "freeplane.desktop" "freeplane.run")
b2sums=('dcf0a285c000a838fa58a42c861096d5a2eb0fd7e12ad9b68ad58a53c526a8d5fb7085183c6ee1e0d51d70772b55394c24cc53dc15cbcde428cdd01692f6e2f8'
        '87c25331e01823e38668e4b394a51a279c05b24b088f4ffc1482d3783e24018da8f9e51b3ad1a62c5a863f85a6ccb30bbe8999cb861dc1b93d5483019644cfa5'
        '24ca56b7c7894b9bb38600b4d37973769243e1bdb221f33125b60bf4f878a3b630775710fab9dee97fa45a69319455037e294860ba7fbd608529982c6b0b1538')

build() {
  cd "$pkgname-${_git_tag}"
  export JAVA_HOME="/usr/lib/jvm/java-$_jdkver-openjdk"
  export PATH="/usr/lib/jvm/java-$_jdkver-openjdk/bin:$PATH"
  /usr/bin/gradle \
    -Dorg.gradle.java.home="/usr/lib/jvm/java-$_jdkver-openjdk" \
    -Dorg.gradle.daemon=false \
    build binZip

  install -dm755 "$srcdir/$pkgname-${_git_tag}/dist"
  unzip -d "$srcdir/$pkgname-${_git_tag}/dist" \
    "$srcdir/$pkgname-${_git_tag}/DIST/${pkgname}_bin-${_majorver}.${_minorver}.${_patchver}.zip"
}

package() {
  install -dm755 "$pkgdir/usr/share/freeplane/"
  cd "$srcdir/$pkgname-${_git_tag}/dist/$pkgname-${_majorver}.${_minorver}.${_patchver}"
  cp -dr --no-preserve='ownership' core doc plugins resources scripts framework.jar freeplane.l4j.ini \
    freeplane.png freeplane.policy freeplane.sh freeplaneConsole.l4j.ini freeplaneIcons.dll \
    freeplanelauncher.jar gitinfo.txt init.xargs license.txt props.xargs \
    "$pkgdir/usr/share/freeplane/"

  # Install license
  install -dm755 "$pkgdir/usr/share/licenses/$pkgname"
  mv license.txt "$pkgdir/usr/share/licenses/$pkgname/license.txt"

  # Install icons
  install -dm755 "$pkgdir/usr/share/pixmaps/"
  mv freeplane.svg "$pkgdir"/usr/share/pixmaps/freeplane.svg

  # Install the desktop entry
  install -Dm644 "$srcdir/freeplane.desktop" "$pkgdir"/usr/share/applications/$pkgname.desktop

  # Install the executable script
  install -Dm755 "$srcdir/freeplane.run" "$pkgdir"/usr/bin/freeplane
}

# vim:set ft=sh sw=2 sts=2 et:
